<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户真实姓名" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入用户真实姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件类型" prop="identityCardType">
        <el-select v-model="queryParams.identityCardType" placeholder="请选择证件类型：1 身份证，2 军官证，3 护照" clearable size="small">
          <el-option label="身份证" value="1" />
          <el-option label="军官证" value="2" />
          <el-option label="护照" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="证件号码" prop="identityCardNo">
        <el-input
          v-model="queryParams.identityCardNo"
          placeholder="请输入证件号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="mobilePhone">
        <el-input
          v-model="queryParams.mobilePhone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="customerEmail">
        <el-input
          v-model="queryParams.customerEmail"
          placeholder="请输入邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-select v-model="queryParams.gender" placeholder="请选择性别" clearable size="small">
          <el-option
            v-for="dict in genderOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="会员级别" prop="customerLevel">
        <el-select v-model="queryParams.customerLevel"  placeholder="请选择会员级别" clearable size="small">
          <el-option value="1" label="普通会员"/>
          <el-option value="2" label="青铜"/>
          <el-option value="3" label="白银"/>
          <el-option value="4" label="黄金"/>
          <el-option value="5" label="钻石"/>
        </el-select>
      </el-form-item>
      <el-form-item label="用户余额" prop="userMoney">
        <el-input
          v-model="queryParams.userMoney"
          placeholder="请输入用户余额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['customer:info:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['customer:info:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['customer:info:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['customer:info:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="自增主键ID" align="center" prop="customerInfId" />
      <el-table-column label="登录名" align="center" prop="customerLogin.loginName" />
      <el-table-column label="用户真实姓名" align="center" prop="customerName" />
      <el-table-column label="证件类型" align="center" prop="identityCardType">
        <template slot-scope="scope">
          <span v-if="scope.row.identityCardType == 1">身份证</span>
          <span v-else-if="scope.row.identityCardType == 2">军官证</span>
          <span v-else-if="scope.row.identityCardType == 3">护照</span>
        </template>
      </el-table-column>
      <el-table-column label="证件号码" align="center" prop="identityCardNo" />
      <el-table-column label="手机号" align="center" prop="mobilePhone" />
<!--      <el-table-column label="邮箱" align="center" prop="customerEmail" />-->
      <el-table-column label="性别" align="center" prop="gender" :formatter="genderFormat" />
      <el-table-column label="注册时间" align="center" prop="registerTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registerTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="会员生日" align="center" prop="birthday" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.customerLogin.userStats" active-value="1" inactive-value="0" @change="handleUserStatusChange(scope.row)"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="会员级别" align="center" prop="customerLevel">
        <template slot-scope="scope">
          <span v-if="scope.row.customerLevel == 1">普通会员</span>
          <span v-else-if="scope.row.customerLevel == 2">青铜</span>
          <span v-else-if="scope.row.customerLevel == 3">3白银</span>
          <span v-else-if="scope.row.customerLevel == 4">黄金</span>
          <span v-else-if="scope.row.customerLevel == 5">钻石</span>
        </template>
      </el-table-column>
      <el-table-column label="用户余额" align="center" prop="userMoney" />
      <el-table-column label="最后修改时间" align="center" prop="modifiedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifiedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

<!--    &lt;!&ndash; 添加或修改客户信息对话框 &ndash;&gt;-->
<!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>-->
<!--      <el-form ref="form" :model="form" :rules="rules" label-width="80px">-->
<!--        <el-form-item label="customer_login表的自增ID" prop="customerId">-->
<!--          <el-input v-model="form.customerId" placeholder="请输入customer_login表的自增ID" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="用户真实姓名" prop="customerName">-->
<!--          <el-input v-model="form.customerName" placeholder="请输入用户真实姓名" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="证件类型：1 身份证，2 军官证，3 护照" prop="identityCardType">-->
<!--          <el-select v-model="form.identityCardType" placeholder="请选择证件类型：1 身份证，2 军官证，3 护照">-->
<!--            <el-option label="请选择字典生成" value="" />-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="证件号码" prop="identityCardNo">-->
<!--          <el-input v-model="form.identityCardNo" placeholder="请输入证件号码" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="手机号" prop="mobilePhone">-->
<!--          <el-input v-model="form.mobilePhone" placeholder="请输入手机号" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="邮箱" prop="customerEmail">-->
<!--          <el-input v-model="form.customerEmail" placeholder="请输入邮箱" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="性别">-->
<!--          <el-radio-group v-model="form.gender">-->
<!--            <el-radio-->
<!--              v-for="dict in genderOptions"-->
<!--              :key="dict.dictValue"-->
<!--              :label="dict.dictValue"-->
<!--            >{{dict.dictLabel}}</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="注册时间" prop="registerTime">-->
<!--          <el-date-picker clearable size="small" style="width: 200px"-->
<!--            v-model="form.registerTime"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="选择注册时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="会员生日" prop="birthday">-->
<!--          <el-date-picker clearable size="small" style="width: 200px"-->
<!--            v-model="form.birthday"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="选择会员生日">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="会员级别：1 普通会员，2 青铜，3白银，4黄金，5钻石" prop="customerLevel">-->
<!--          <el-input v-model="form.customerLevel" placeholder="请输入会员级别：1 普通会员，2 青铜，3白银，4黄金，5钻石" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="用户余额" prop="userMoney">-->
<!--          <el-input v-model="form.userMoney" placeholder="请输入用户余额" />-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--        <el-button @click="cancel">取 消</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->
  </div>
</template>

<script>
import { listInfo, exportInfo,changeInfoStatus } from "@/api/customer/info";
// , getInfo, delInfo, addInfo, updateInfo
export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 性别字典
      genderOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerId: null,
        customerName: null,
        identityCardType: null,
        identityCardNo: null,
        mobilePhone: null,
        customerEmail: null,
        gender: null,
        customerLevel: null,
        userMoney: null,
      },
      // 表单参数
      form: {},
      // // 表单校验
      // rules: {
      //   customerId: [
      //     { required: true, message: "customer_login表的自增ID不能为空", trigger: "blur" }
      //   ],
      //   customerName: [
      //     { required: true, message: "用户真实姓名不能为空", trigger: "blur" }
      //   ],
      //   identityCardType: [
      //     { required: true, message: "证件类型：1 身份证，2 军官证，3 护照不能为空", trigger: "change" }
      //   ],
      //   registerTime: [
      //     { required: true, message: "注册时间不能为空", trigger: "blur" }
      //   ],
      //   customerLevel: [
      //     { required: true, message: "会员级别：1 普通会员，2 青铜，3白银，4黄金，5钻石不能为空", trigger: "blur" }
      //   ],
      //   userMoney: [
      //     { required: true, message: "用户余额不能为空", trigger: "blur" }
      //   ],
      //   modifiedTime: [
      //     { required: true, message: "最后修改时间不能为空", trigger: "blur" }
      //   ]
      // }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_user_sex").then(response => {
      this.genderOptions = response.data;
    });
  },
  methods: {
    /** 查询客户信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 性别字典翻译
    genderFormat(row, column) {
      return this.selectDictLabel(this.genderOptions, row.gender);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        customerInfId: null,
        customerId: null,
        customerName: null,
        identityCardType: null,
        identityCardNo: null,
        mobilePhone: null,
        customerEmail: null,
        gender: "0",
        registerTime: null,
        birthday: null,
        customerLevel: null,
        userMoney: null,
        modifiedTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.customerInfId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加客户信息";
    // },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const customerInfId = row.customerInfId || this.ids
    //   getInfo(customerInfId).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改客户信息";
    //   });
    // },
    // /** 提交按钮 */
    // submitForm() {
    //   this.$refs["form"].validate(valid => {
    //     if (valid) {
    //       if (this.form.customerInfId != null) {
    //         updateInfo(this.form).then(response => {
    //           if (response.code === 200) {
    //             this.msgSuccess("修改成功");
    //             this.open = false;
    //             this.getList();
    //           }
    //         });
    //       } else {
    //         addInfo(this.form).then(response => {
    //           if (response.code === 200) {
    //             this.msgSuccess("新增成功");
    //             this.open = false;
    //             this.getList();
    //           }
    //         });
    //       }
    //     }
    //   });
    // },
    // /** 删除按钮操作 */
    // handleDelete(row) {
    //   const customerInfIds = row.customerInfId || this.ids;
    //   this.$confirm('是否确认删除客户信息编号为"' + customerInfIds + '"的数据项?', "警告", {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning"
    //     }).then(function() {
    //       return delInfo(customerInfIds);
    //     }).then(() => {
    //       this.getList();
    //       this.msgSuccess("删除成功");
    //     }).catch(function() {});
    // },

    /** 停用启用状态修改 */
    handleUserStatusChange(row){
      console.log(" row.customerLogin.userStats:"+row.customerLogin.userStats);
      let text = row.customerLogin.userStats === "1" ? "启用" : "停用";
      this.$confirm(
        '确认要"' + text + '""' + row.customerName + '"人员的账号信息吗?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return changeInfoStatus(row.customerLogin.customerId, row.customerLogin.userStats);
        })
        .then(() => {
          this.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.customerLogin.userStats = row.customerLogin.userStats === "0" ? "1" : "0";
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有客户信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
